package com.suse.jd_system_server.controller;

import com.suse.jd_system_server.dao.UserDao;
import com.suse.jd_system_server.entity.User;
import com.suse.jd_system_server.service.impl.userTestyServiceImpl_pb;
import com.suse.jd_system_server.utils.Result;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
@CrossOrigin()
public class UserTestController {

    @Autowired
    public UserDao userDao;

    @Autowired
    private userTestyServiceImpl_pb serviceImpl_pb;

    @GetMapping("getUser")
    public Result getUser(){
        System.out.println("getUser");
        User selects = userDao.selects(1L);
        return Result.buildSuccess(selects);
    }

    @PostMapping("/loginMoni")
    public Result loginMoni(@RequestBody User user, HttpServletRequest  request){
        /**
         *
         * ************登录完成逻辑*********
         *
         */
//        System.out.println("user:"+user);
        //存储session
        HttpSession session = request.getSession();
        session.setAttribute("userName",user.getUserName());
        session.setAttribute("userId",user.getUserId());
//        System.out.println(session.getAttribute("userName"));
//        System.out.println(session.getAttribute("userId"));

        return Result.buildSuccess();
    }

    @GetMapping("/logTest")
    public Result logTest(){
        serviceImpl_pb.test();
        return Result.buildSuccess();
    }
}
